package microcredit.gui.selector;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.KeyStroke;

import microcredit.gui.base.BaseAction;

public class OkCancelButtonPanel extends AbstractButtonPanel {

	protected final BaseAction okAction = createOkAction();
	protected final BaseAction cancelAction = createCancelAction();
	
	public OkCancelButtonPanel() {
		addExpander();
		addAction(okAction);
		addAction(cancelAction);
	}
	
	protected BaseAction createOkAction() {
		return new OkAction(this);
	}
	
	protected BaseAction createCancelAction() {
		return new CancelAction(this);
	}
	
	protected void okPerformed(ActionEvent event) throws Throwable {
	}
	
	protected void cancelPerformed(ActionEvent event) throws Throwable {
		
	}
	
	protected class OkAction extends BaseAction {
		public OkAction(Component parent) {
			super(parent);
			putValue(NAME, "Ok");
			putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
		}

		@Override
		public void perform(ActionEvent e) throws Throwable {
			okPerformed(e);
		}
	}
	protected class CancelAction extends BaseAction {
		public CancelAction(Component parent) {
			super(parent);
			putValue(NAME, "Cancel");
			putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
		}

		@Override
		public void perform(ActionEvent e) throws Throwable {
			cancelPerformed(e);
		}
	}
	
}
